package org.fullhappy.view.showroom;

import java.io.IOException;
//import java.io.PrintWriter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
//import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import com.sun.jersey.server.impl.application.WebApplicationContext;

public class ShowRoom implements Filter {

    @Override
    public void init(FilterConfig config) throws ServletException {
        //
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        //String sessionId = request.getSession(true).getId();
        HttpServletResponse response = (HttpServletResponse) res;
        String requestURI = request.getRequestURI();
        String[] paths = requestURI.substring(1).split("/");
        RequestDispatcher dispatcher = null;
        if(paths.length == 2){
        	dispatcher = request.getRequestDispatcher("/gallery.jsp");
        	dispatcher.forward(request, response);
        	
        }else if(paths.length == 3){
        	dispatcher = request.getRequestDispatcher("/gallery/product.jsp");
        	dispatcher.forward(request, response);
        }
        else{
        	response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        }
        
    }

    @Override
    public void destroy() {
        //
    }
//    
//    @SuppressWarnings("unused")
//	private void menu(HttpServletRequest request, HttpServletResponse response) throws IOException{
//    	response.setContentType("application/json");
//    	response.setCharacterEncoding("UTF-8");
//        PrintWriter out = response.getWriter();
//        
//        String s= ""+
//        		"		[{'title':'hone','link':'/home.html'},                                                                                                                                                                                                                                                                                       "+
//        	    "            {'title':'product','link':'','child':                                                                                                                                                                                                                                                                                   "+
//        	    "            	[                                                                                                                                                                                                                                                                                                                    "+
//        	    "            	 {'title':'Product1','link':'','child':[{'title':'Product11','link':'gallery.html'},{'title':'Product12','link':'gallery.html'},{'title':'Product13','link':'gallery.html'},{'title':'Product14','link':'gallery.html'},{'title':'+ Add New Item','link':'javascript:(new Menu()).openLightBoxAddCategory();'}]},                                 "+
//        	    "            	 {'title':'Product2','link':'','child':[{'title':'Product21','link':'gallery.html'},{'title':'Product22','link':'gallery.html'},{'title':'+ Add New Item','link':'javascript:(new Menu()).openLightBoxAddCategory();'}]},                                                                                                                                 "+
//        	    "            	 {'title':'Product3','link':'','child':[{'title':'Product31','link':'gallery.html'},{'title':'Product32','link':'gallery.html'},{'title':'Product33','link':'gallery.html'},{'title':'Product34','link':'gallery.html'},{'title':'Product35','link':'gallery.html'},{'title':'+ Add New Item','link':'javascript:(new Menu()).openLightBoxAddCategory();'}]},   "+
//        	    "            	 {'title':'Product4','link':'','child':[{'title':'Product41','link':'gallery.html'},{'title':'+ Add New Item','link':'javascript:(new Menu()).openLightBoxAddCategory();'}]},                                                                                                                                                                     "+
//        	    "            	 {'title':'Product5','link':'','child':[{'title':'Product51','link':'gallery.html'},{'title':'Product52','link':'gallery.html'},{'title':'+ Add New Item','link':'javascript:(new Menu()).openLightBoxAddCategory();'}]},                                                                                                                                                                                   "+
//        	    "            	 {'title':'Product6','link':'','child':[{'title':'Product61','link':'gallery.html'},{'title':'Product62','link':'gallery.html'},{'title':'+ Add New Item','link':'javascript:(new Menu()).openLightBoxAddCategory();'}]},                                                                                                                                     "+
//        	    "            	 {'title':'Add New ','link':'javascript:(new Menu()).openLightBoxAddGallery();','child':[{'title':'--','link':''},{'title':'--','link':''}]}                                                                                                                      "+
//        	    "            	]                                                                                                                                                                                                                                                                                                                    "+
//        	    "			},                                                                                                                                                                                                                                                                                                                       "+
//        	    "            {'title':'Sale','link':'sale.html'},                                                                                                                                                                                                                                                                                    "+
//        	    "            {'title':'About Us','link':'sale.html'},                                                                                                                                                                                                                                                                                "+
//        	    "            {'title':'Contact Us','link':'','child':[{'title':'Address','link':''},{'title':'Send Email','link':''}]}]                                                                                                                                                                                                              "+
//        		"";
//        out.println(s);
//        out.flush();
//        out.close();
//    }
//    
//    @SuppressWarnings("unused")
//	private void product(HttpServletRequest request, HttpServletResponse response) throws IOException{    	
//        
//        String requestURI = request.getRequestURI();
//        String[] paths = requestURI.substring(1).split("/");
//        //   product/123
//        if(paths.length>=3){
//        	String id = paths[2];
//        	String s= getProductResource(id);        	
//        	response.setContentType("application/json");
//        	response.setCharacterEncoding("UTF-8");
//        	
//            PrintWriter out = response.getWriter();
//            out.println(s);
//            out.flush();
//            out.close();
//        }else {
//        	response.setStatus(HttpServletResponse.SC_NOT_FOUND);
//		}
//        
//    }
//
//	private String getProductResource(String id) {
//		return 	"{"+
//		        		"	'title' : 'Đầm ren tay con duyên dáng MS 122',											"+				
//						"	'description' : '- Đầm được may bằng chất liệu phi bóng nhập khẩu,'+					"+					
//						"					' mềm mại, thoáng mát, mịn màng. <br/> - Kiểu dáng thanh lịch,'+		"+																		
//						"					' kết hợp kiểu cánh	dơi với đầm tôn vẻ sang trọng của bạn gái.'+		"+								
//						"					' <br/> - Màu sắc:	nhiều màu. <br/> - Đầm free size, thích hợp'+		"+								
//						"					' cho các bạn gái từ 55kg trở xuống. <br/> - Đầm phi sẽ giúp bạn'+		"+								
//						"					' dịu dàng khi dạo phố, thanh lịch khi đi làm, sang trọng khi đi'+		"+								
//						"					' dự tiệc. <br/> -	Có thể mua để làm quà tặng ý nghĩa dành cho'+		"+								
//						"					' các bạn gái',															"+
//						"	'price':'499.000đ',																		"+
//						"	'images':['http://www.vatgia.com/pictures_fullsize/lku1300533839.jpg',					"+					
//						"	          'http://www.vatgia.com/pictures_fullsize/dyq1301283412.jpg',					"+					
//						"	          'http://www.vatgia.com/pictures_fullsize/xjq1301931051.jpg',					"+					
//						"	          'http://www.vatgia.com/pictures_fullsize/iaw1304662568.jpg',					"+					
//						"	          'http://www.vatgia.com/pictures_fullsize/fqu1304663118.jpg',					"+					
//						"	          'http://www.vatgia.com/pictures_fullsize/fqu1304663118.jpg',					"+
//						"	          'http://www.vatgia.com/pictures_fullsize/fqu1304663118.jpg']					"+					
//						"}";
//	}
 
 }